package com.xuecheng.ucenter.service.impl;


import com.xuecheng.ucenter.service.SendMailService;
import com.xuecheng.ucenter.util.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class SendMailServiceImpl implements SendMailService {
    @Autowired
    private JavaMailSender javaMailSender;
    // 发送人
    private String from = "2575603138@qq.com";
    // 标题
    private String subject = "验证码";
    @Override
    public String sendMail(String to) {
        SimpleMailMessage message = new SimpleMailMessage();
        String code4String = ValidateCodeUtils.generateValidateCode4String(4);
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(code4String);
        javaMailSender.send(message);
        return code4String;
    }
}
